import java.util.LinkedList;
import java.util.Queue;

public class MyQueue {
    private final int[] elem;
    private int front;
    private int rear;
    public MyQueue(int k){
        this.elem = new int[k];
    }
    public boolean isEmpty(){
        return this.front == this.rear;
    }
    public boolean isFull(){
        return (this.rear + 1) % this.elem.length == this.front;
    }

    public boolean enQueue(int value){
        if(isEmpty()){
            return false;
        }
        this.elem[this.rear] = value;
        this.rear = (this.rear + 1) % this.elem.length;
        return true;
    }

    public boolean deQueue(){
        if(isEmpty()){
            return false;
        }
        this.front = (this.front + 1) % this.elem.length;
        return true;
    }

    public int Front(){
        if(isEmpty()){
            return -1;
        }
        return this.elem[this.front];
    }
    public int Rear(){
        if(isEmpty()){
            return -1;
        }
        int index = this.rear == 0 ? this.elem.length - 1 : this.rear - 1;
        return this.elem[index];
    }
}
